To achieve voice over the chart elements, data, and some actions, we can use the Hit Test API and event subscription.
Possible use-cases:
-
User selects axes with the voice over reading the range of the axis that is visible on the screen.
-
User clicks on a series data point with the voice over reading the coordinates of the selected point.
-
User zooms or pans chart with the voice over describing the new visible ranges of the axes.
Adding VoiceOver to Data Series using HitTest API
This example demonstrates how to add VoiceOver to announce points on FastLineRenderableSeries. Voice over functionality is provided by SpeechSynthesisUtterance API.
1. We will start from a basic chart definition:
This definition instantiates a chart with named axes and line series.
2. Subscribe to mouse click events on the chart:
3. Add logic to check if line series are clicked in hitTestDataPoints:
Notice that coordinates passed to the Hit Test method are multiplied by DpiHelper.PIXEL_RATIO to be scaled accordingly to display and browser configurations. See also Retina Support and Browser Zoom, Hit Test API Documentation.
4. Now let's define the voiceOverDataPoint function which will format the coordinates and announce them using VoiceOver:
where announcePointOnDataSeries is implemented as following:
Now upon clicking on a point of the line series we should get its coordinates announced with speech synthesis and logged to the console.
VoiceOver for Axes
VoiceOver upon chart axes also could be easily implemented:
Here we have defined hitTestAxes function and used it in the event listener.
The announceAxis and isPointWithinAxis will look like this:
This example should result in VoiceOver describing axis title and its visible range upon clicking.
VoiceOver for visible range updates
The visible range changes detection on an axis could be added as following:
Visible range changes detection |
Copy Code
|
---|---|
const announceYRangeChange = debounce(announceWithSpeechSynthesis); const announceXRangeChange = debounce(announceWithSpeechSynthesis); // add announcement of axis range changes yAxis.visibleRangeChanged.subscribe((args) => { const { min, max } = args.visibleRange; const from = yAxis.labelProvider.formatLabel(min); const to = yAxis.labelProvider.formatLabel(max); const announcement = `${yAxis.axisTitle} range changed, now it's from ${from} to ${to}.`; announceYRangeChange(announcement); }); xAxis.visibleRangeChanged.subscribe((args) => { const { min, max } = args.visibleRange; const from = xAxis.labelProvider.formatLabel(min); const to = xAxis.labelProvider.formatLabel(max); const announcement = `${xAxis.axisTitle} range changed, now it's from ${from} to ${to}.`; announceXRangeChange(announcement); }); |
Let's add some zoom&pan modifiers to demonstrate the result:
Add modifiers |
Copy Code
|
---|---|
import { MouseWheelZoomModifier } from "scichart/Charting/ChartModifiers/MouseWheelZoomModifier"; import { ZoomExtentsModifier } from "scichart/Charting/ChartModifiers/ZoomExtentsModifier"; import { ZoomPanModifier } from "scichart/Charting/ChartModifiers/ZoomPanModifier"; // ... sciChartSurface.chartModifiers.add( new ZoomPanModifier(), new ZoomExtentsModifier(), new MouseWheelZoomModifier(), ); |
Now when using the chart modifiers you should be able to observe them getting logged to the console.